<%@ page language="java" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
${aier_doctype}
<html <s:property value="aier_html_xmlns" escape="false"/>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>${aier_title}</title>
<meta content="${aier_keywords}" name="keywords">
<meta content="${aier_description}" name="description">
<link href="${aier_css_url}jc/chosen.css" rel="stylesheet">
<link rel="stylesheet" href="${aier_css_url}jq/jq.css" />
<link rel="stylesheet" href="${aier_css_url}${aier_jqui_css}/ui.css" />
<link rel="stylesheet" href="${aier_css_url}comm/text.css" />
<link rel="stylesheet" href="${aier_css_url}social/module/jq-msg.css" />
<link rel="stylesheet" href="${aier_css_url}comm/fb.css" />

<script type="text/javascript" src="${aier_js_url}j.js"></script>
<script type="text/javascript" src="${aier_js_url}b.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/hh/ui.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/msg.js"></script>
<script type="text/javascript" src="${aier_js_url}lib/block.js"></script>
<script type="text/javascript" src="${aier_js_url}lib/arrayList.js"></script>
<script type="text/javascript" src="${aier_js_url}jc/cj.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/jq.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/cn.js"></script>
<script type="text/javascript" src="${aier_js_url}comm/text.js"></script>
<title>分配短信</title>
</head>
<script type="text/javascript">
$(document).ready(function(){
    $("#schoolinfo").jqGrid({                
        url:'${aier_url}${aier_urijs}message_searchSchool${aier_suffix}',                
        datatype:"json",                
        mtype:'GET',
        height:'230',
        width:'600',              
        colNames:['学校名称','可用短信条数','分配短信','分配历史记录','sid'],                
        colModel:[                    
        {name:'name',index:'name',width:160,align:'center'},
        {name:'mesCount',index:'count',width:80,align:'center'},
        {name:'revoked',index:'revoked',width:80,align:'center',sortable : false},
        {name:'revoked1',index:'revoked1',width:80,align:'center',sortable : false},                   
        {name:'sid',index:'sid',hidden : true},
        ],
        jsonReader: {
            root:"schoolsList",
            page: "page",
            total: "page_count",
            records : "count",
            repeatitems: false
        },
        pager: jQuery("#schoolpage"),
        prmNames : {page:"page",sort: "sort"},
        rowNum: 10,
        sortname: 'cid',
        hidegrid: false,
        sortorder: 'asc',
        viewrecords: true,
        caption: '分配短信',
        gridComplete:function(){
            var ids=jQuery("#schoolinfo").jqGrid('getDataIDs');
            for(var i=0; i<ids.length; i++){
                var id=ids[i]; 
                
                var re = "<a href='javascript:;' class='jqtrow' onclick='assign("+ id + ")'>分配短信</a>";
                var re1 = "<a href='javascript:;' class='jqtrow' onclick='detail("+ id + ")'>分配历史记录</a>";
                
                jQuery("#schoolinfo").jqGrid('setRowData', ids[i], {revoked:re,revoked1:re1});
            }
        }
    }).navGrid("#schoolpage", { edit: false, add: false, del: false, search: false });
}); 
</script>
<body style="background-color: #EEF2FB;">
    
    <div style="background-color: #EEF2FB;width: 100%;height: 700px; ">	
		<div id="tabs">
			<ul>
				<li><a href="#tabs-1">分配短信</a></li>
			</ul>
			<div id="tabs-1" style="height: 500px;">
				<div class="d_content">
                    <div class="d_scnOut">
                        <div class="d_scname">
                            <label for="name">学校地址:</label>
                        </div>
                        <div class="sel_region">
                            <s:action name="cityutil" namespace="/common"
                                executeResult="true">
                                <s:param name="cityid">-1</s:param>
                            </s:action>
                        </div>
                    </div>
	                <div class="d_scnOut">
                        <div class="d_scname" style="margin-left: 0px;">
                            <label for="name">学校名称: </label>
                        </div>
                        <div class="d_sctext">
                            <input type="text" id="sname" />
                        </div>
                    </div>
	                <div style="margin-left: 400px;margin-top: -47px;">
	                    <button onclick="search();"
	                        class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
	                        role="button" aria-disabled="false">
	                        <span class="ui-button-text">查询</span>
	                    </button>
	
	                </div>
					<!-- 表格 -->
					<div style="margin-left: 0px;margin-top: 10px;">
						<table id="schoolinfo"></table>
						<div id="schoolpage"></div>
					</div>
				</div>
				
				<!-- 弹出层内容 分配短信-->
                <div id="assign_message" title="分配短信" style="display: none;">
                    <div class="d_scnOut" style="margin-top: 10px;">
                        <div class="d_scname" style="font-size: 14px;">
                            <label>学校名称:</label>
                        </div>
                        <div class="d_sctext" style="font-size: 14px;">
                            <span id="name" class="txt_scname"></span>
                        </div>
                    </div>
                    <div class="d_scnOut">
                        <div class="d_scname" style="font-size: 14px;">
                            <label>短信条数:</label>
                        </div>
                        <div class="d_sctext" style="font-size: 14px;">
                            <input type="text" id="count" class="txt_scname">
                        </div>
                    </div>
                    <button style="margin-top: 30px;" onclick="assignMes();"
                            class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
                            role="button" aria-disabled="false">
                            <span class="ui-button-text">分配</span>
                    </button>
                </div>
                
			</div>
		</div>
	</div>
</body>
<script type="text/javascript">
	$("#tabs").tabs();
	// 弹出层
	$(function() {
	    $("#assign_message").dialog({
	        //背景变暗
	        modal: true,
	        autoOpen : false,
	        show : "blind",
	        width : "400",
	        height : "200"
	    });
	
	});
	var sid;
    function search(){
        var pcid = -1;
        if(acity.cid>-1){
            pcid = acity.cid;
        }
        jQuery("#schoolinfo").jqGrid('setGridParam',{url:'${aier_url}${aier_urijs}message_searchSchool${aier_suffix}'+"?cid="+pcid+"&sname="+$("#sname").val(),page:1}).trigger("reloadGrid");
    }
    
    function assign(id) {
        sid = jQuery("#schoolinfo").jqGrid('getRowData', id).sid;
        $("#name").html(jQuery("#schoolinfo").jqGrid('getRowData', id).name);
        $("#assign_message").dialog("open");
    }
    
    function assignMes() {
        var count=$("#count");
        var countVal=count.val();
        var pattern = new RegExp(/^[0-9]{0,6}$/);    
        var isnum = pattern.exec(countVal);
        if(isnull(isnum)){
            count.addClass("ui-state-error");
            $().message("请输入分配短信条数!");
            count.focus();
            return;
        }else{
            count.removeClass( "ui-state-error" );
        }
        
        var fun = function(data) {
            if(1==data.s){
                count.val("");
                $().message("分配成功!");
                $("#schoolinfo").trigger("reloadGrid");
                $("#assign_message").dialog("close");
            }else{
                $().message("分配失败,请稍后再试!");
            }
        };
        exeAjax(ajaxUrl("${aier_url}${aier_urijs}message_assignMessage${aier_suffix}"), fun, 
        {"sid" :sid,
         "mcount":countVal
         });
    }
    
    function detail(id) {
        window.location.href = "${aier_url}${aier_uri}message_detail${aier_suffix}?sid="+jQuery("#schoolinfo").jqGrid('getRowData', id).sid;
    }

</script>
</html>